package app.netant.book.shushu8;

import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import app.netant.book.base.BaseDetail;
import app.netant.book.base.BaseEntity;
import app.netant.book.base.BasePage;
import cn.lily.com.enviroment.Enviroment;

public class Shushu8Page extends BasePage {

	public Shushu8Page(String netSite) {
		super(netSite);
		this.tableKey = "shushu8";
		this.selectKey = ".listcon.clearfix .listconl ul li span.width369.jhfd a.green";
		this.preHref = "http://www.shushu8.com";
	}

	@Override
	public String buildHref(Element element) {	
		String href = element.attr("href");
		if(href.startsWith("/")){
			href = this.preHref + href;
		}
		
		Shushu8Page page = new Shushu8Page(href);
		href = page.stepHref();
		
		return href;
	}
	
	public String stepHref(){
		
		Elements parts = this.select(".clearfix.wrap980 .wrap706 .con_lwrap .r420 .r_tools a.downbook");
		if(parts.size()>0){
			String href = parts.get(0).attr("href");
			if(href.startsWith("/")){
				href = this.preHref + href;
			}
			return href;
		}	
		return null;
	}

	@Override
	public BaseEntity buildEntity() {
		return new Shushu8Entity();
	}

	@Override
	public BaseDetail buildDetail(String href) {
		return new Shushu8Detail(href);
	}

	@Override
	public void afterEntity(BaseEntity entity, Element element) {
		
	}
	
	public static void main(String[] args) {
		Enviroment.createEnv();
		Enviroment.getEnv().getLogBean().beginLog();
		Shushu8Page page = new Shushu8Page("http://www.shushu8.com/xuanhuan/");
		page.analyseHref();
	}
	
}
